package com.st.dao.impl;

import java.util.List;

import com.st.dao.IDeptDao;
import com.st.enity.Dept;
import com.st.util.DBUtil;

public class DeptDaoImpl implements IDeptDao{
	private DBUtil dbUtil = new DBUtil();
	@Override
	public List<Dept> selectAll() {
		String sql = "select * from dept";
		return dbUtil.query(sql, null, Dept.class);
	}
	@Override
	public List<Dept> selectByKey(String key) {
		String sql = "select * from dept where did like ? or dname like ? or droom like ? or dphone like?";
		Object[] params = {"%"+key+"%","%"+key+"%","%"+key+"%","%"+key+"%"};
		return dbUtil.query(sql, params, Dept.class);
	}

	@Override
	public int modify(Dept dept, String oldpassword, String newpassword, String newpassword2) {
		return 0;
	}

	@Override
	public int update(Dept dept, Integer id) {
		String sql = "update dept set dname=?, droom=? ,dphone=? where did=?";
		Object[] params = {dept.getDname(),dept.getDroom(),dept.getDphone(),id};
		System.out.println(dept);
		return dbUtil.update(sql, params);
	}

	@Override
	public int add(Dept dept) {
		String sql = "insert into dept (dname, droom,dphone) value(?,?,?)";
		Object[] params = {dept.getDname(),dept.getDroom(),dept.getDphone()};
		return dbUtil.update(sql, params);
	}

	@Override
	public int remove(int id) {
		String sql = "delete from dept where did=?";
		Object[] params = {id};
		return dbUtil.update(sql, params);
	}

}
